import service from '../../utils/request';
Page({
  // 响应式数据
  data: {
    bannerArr: [],
    categoryArr:[],
    goodsArr:[],
    recommendArr:[]
  },
  // 页面加载
  onLoad() {
    // 轮播图
    this.getBanner();
    // 获取商品分类
    this.getCategory();
    // 猜你喜欢
    this.getContainer();
    // 热门推荐
    this.getRecommend();
  },
  // 轮播图
  async getBanner() {
    const result = await service({
      url: '/mall-api/index/findBanner'
    });
    if (result.code === 200) {
      this.setData({
        bannerArr: result.data
      })
    }
  },
  // 商品分类
  async getCategory() {
    const result = await service({
      url: '/mall-api/index/findCategory1'
    });
    if (result.code === 200) {
      this.setData({
        categoryArr:result.data
      })
    }
  },
  // 猜你喜欢
  async getContainer(){
    const result = await service({
      url:'/mall-api/index/findListGoods'
    });
    if(result.code === 200) {
      this.setData({
        goodsArr:result.data
      })
    }
  },
  // 热门推荐
  async getRecommend(){
    const result = await service({
      url:'/mall-api/index/findRecommendGoods'
    });
    if(result.code === 200) {
      this.setData({
        recommendArr:result.data
      })
    }
  },
  goGoodsList(){
    wx.navigateTo({
      url: '/pages/goodsList/goodsList',
    })
  },
})